public class Solution165 {
    public int compareVersion(String version1, String version2) {
        int value1 = 0, value2 = 0;
        int pos1 = 0, pos2 = 0, n1 = version1.length(), n2 = version2.length();
        while (pos1 < n1 || pos2 < n2) {
            while (pos1 < n1 && version1.charAt(pos1) != '.') {
                int c = version1.charAt(pos1) - '0';
                pos1++;
                if (c != 0 || value1 > 0) {
                    value1 = value1 * 10 + c;
                }
            }
            while (pos2 < n2 && version2.charAt(pos2) != '.') {
                int c = version2.charAt(pos2) - '0';
                pos2++;
                if (c != 0 || value2 > 0) {
                    value2 = value2 * 10 + c;
                }
            }
            if (value1 < value2) {
                return -1;
            } else if (value1 > value2) {
                return 1;
            }
            pos1++;
            pos2++;
            value1 = 0;
            value2 = 0;
        }
        return 0;
    }
}
